<include file='Public:head' />
<body class="J_scroll_fixed">
<div class="wrap J_check_wrap">
	<div class="nav">
		<ul class="cc">
		      <li ><a href="{:U('index',array('position_psid'=>$_GET['position_psid'],'verifystate'=>2))}">广告列表</a></li>
		      <li  class="current"><a href="">添加广告</a></li>
    	</ul>
	</div>
	<div class="h_a">广告属性</div>
	<form action="{:U('Ad/add')}" method="post" class="J_ajaxForms"  name="myform" id="myform">
		<div class="table_full">
			<table width="100%"  class="table_form" >
				<tr>
					<th width="120">广告位置：</th>
					<td class="y-bg">
						<select name="position_psid"  id='position_psid'>
							<option value="">请选择广告位置</option>
							<foreach name='position' item='v'>
							   	<option value='{$v.psid}' <if condition='$v["psid"] eq $_GET["position_psid"]'> selected='selected' </if>>{$v.position_name}</option>
							</foreach>
						</select>
					</td>
				</tr>
				<tr>
					<th width="120">广告名称：</th>
					<td class="y-bg">
						<input type="text" class="input" name="name" id="name" size='50' value="" />
					</td>
				</tr>
				<if condition='C("cfg_language_en")'>
				<tr>
					<th width="120">(英)广告名称：</th>
					<td class="y-bg">
						<input type="text" class="input" name="name_en" id="name_en" size='50' value="" />
					</td>
				</tr>
				</if>

				<tr>
					<th width="120">图片：</th>
					<td class="y-bg">
						<input type="text" name="pic" id="pic" value="" size="50" class="input"  ondblclick="image_priview(this.value);"/> 
              			<input type="button" class="button" onclick="javascript:flashupload('image_images', '图片上传','pic',submit_images,'{$Think.const.CONTROLLER_NAME}',1,1,'{$Think.Config.cfg_image}')" value="上传图片" /><span class="gray"> 双击可以查看图片！</span>
					</td>
				</tr>
				
				<if condition='C("cfg_language_en")'>
				<tr>
					<th width="120">(英)图片：</th>
					<td class="y-bg">
						<input type="text" name="pic_en" id="pic_en" value="" size="50" class="input"  ondblclick="image_priview(this.value);"/> 
              			<input type="button" class="button" onclick="javascript:flashupload('image_images', '图片上传','pic_en',submit_images,'{$Think.const.CONTROLLER_NAME}',1,1,'{$Think.Config.cfg_image}')" value="上传图片" /><span class="gray"> 双击可以查看图片！</span>
					</td>
				</tr>
				</if>

				<tr>
					<th width="120">广告链接：</th>
					<td class="y-bg">
						<textarea name='url' id='url' style="width:90%;height:80px"></textarea>
					</td>
				</tr>
				<tr>
					<th width="120">排序：</th>
					<td class="y-bg">
						<input type="text" class="input" name="sort" id="sort" value="100" />
					</td>
				</tr>
				<tr>
					<th width="120">状态：</th>
					<td class="y-bg">
					<label >
						<input type="radio" name='verifystate' value="1"> 未审核
					</label>
					<label >
						<input type="radio" name='verifystate' value="2" checked="checked"> 审核通过
					</label>
					</td>
				</tr>

				
				
			</table>
		</div>
		<div class="">
			<div class="btn_wrap_pd">
			
				<button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">添加</button>

			</div>
		</div>
	</form>
</div>
<script type="text/javascript" src="__ROOT__/Core/Org/common.js"></script>
<script type="text/javascript" src="__ROOT__/Core/Org/content_addtop.js"></script>
<script type="text/javascript">

$(function(){
	
    Wind.use('validate', 'ajaxForm', 'artDialog', function () {
        var form = $('form.J_ajaxForms');
        //ie处理placeholder提交问题
        if ($.browser.msie) {
            form.find('[placeholder]').each(function () {
                var input = $(this);
                if (input.val() == input.attr('placeholder')) {
                    input.val('');
                }
            });
        }
        //表单验证开始
        form.validate({
			//是否在获取焦点时验证
			onfocusout:false,
			//是否在敲击键盘时验证
			onkeyup:false,
			//当鼠标掉级时验证
			onclick: false,
            //验证错误
            showErrors: function (errorMap, errorArr) {
				//errorMap {'name':'错误信息'}
				//errorArr [{'message':'错误信息',element:({})}]
				try{
					$(errorArr[0].element).focus();
					art.dialog({
						id:'error',
						icon: 'error',
						lock: true,
						fixed: true,
						background:"#CCCCCC",
						opacity:0,
						content: errorArr[0].message,
						cancelVal: '确定',
						cancel: function(){
							$(errorArr[0].element).focus();
						}
					});
				}catch(err){
				}
            },
            //验证规则
            rules: {
            	"position_psid":{
					required:true
				},
				"name":{
					required:true
				},
				"sort":{
					required:true
				},
				
			},
            //验证未通过提示消息
        messages: {
        		"position_psid":{
					required:'请选择广告位置'
				},
				"name":{
					required:"广告名称不能为空！"
				},
				"sort":{
					required:"排序不能为空！"
				},
				
			},
            //给未通过验证的元素加效果,闪烁等
            highlight: false,
            //是否在获取焦点时验证
            onfocusout: false,
            //验证通过，提交表单
            submitHandler: function (forms) {
                $(forms).ajaxSubmit({
                    url: form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
                    dataType: 'json',
                    beforeSubmit: function (arr, $form, options) {
                        
                    },
                    success: function (data, statusText, xhr, $form) {
                        if(data.status)
                        {
							resultTip({error:0,msg:data.info});
                         	setInterval(function()
                            {
                              window.location.href=data.url;
                            },1000);
						}
						else
						{
							isalert(data.info);
						}
                    }
                });
            }
        });
    });
});




</script>
</body>
</html>